package com.shycloud.mido.opter.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shycloud.mido.opter.api.vo.DeviceInfoVO;
import lombok.AllArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shycloud.mido.opter.api.entity.StockDeviceInfo;
import com.shycloud.mido.opter.mapper.StockDeviceInfoMapper;
import com.shycloud.mido.opter.service.StockDeviceInfoService;

@Service
@AllArgsConstructor
public class StockDeviceInfoServiceImpl extends ServiceImpl<StockDeviceInfoMapper, StockDeviceInfo> implements StockDeviceInfoService {

	/** 硬件追溯模块 service */
	private StockDeviceInfoMapper stockDeviceInfoMapper;

	/**
	 * 查询智能追溯列表
	 *
	 * @param udid
	 * @param nameOrPhone
	 * @param status
	 * @param type
	 * @param user
	 * @param page
	 * @return com.baomidou.mybatisplus.core.metadata.IPage<com.shycloud.mido.opter.api.vo.DeviceInfoVO>
	 * @author nianhua.jiang
	 * @date 2020/9/24 15:48
	 **/
	@Override
	public IPage<DeviceInfoVO> getDeviceInfoList(String udid, String nameOrPhone, String status, String type, String user, Page page) {

		//运营商电话
		String optPhone = StringUtils.EMPTY;
		//运营商名称
		String optName = StringUtils.EMPTY;

		//判断是客户名称还是手机号
		if (StringUtils.isNumeric(nameOrPhone)) {
			optPhone = nameOrPhone;
		} else {
			optName = nameOrPhone;
		}

		//激活用户手机号
		String userPhone = StringUtils.EMPTY;
		//激活用户的昵称
		String userName = StringUtils.EMPTY;

		if (StringUtils.isNumeric(user)) {
			userPhone = user;
		} else {
			userName = user;
		}

		return stockDeviceInfoMapper.getDeviceInfoList(page, udid, optPhone, optName, status, type, userPhone, userName);
	}
}
